﻿namespace EFS.RC.CC.CH.Tables
{
	public static class SurveySessionAnswersInfos
	{
		/// Returns an object from a data row
		public static EFS.RC.CC.CH.Entities.Surveys.Sessions.AnswerInfo FromTableRow(System.Data.DataRow row)
		{
			// check
			EFS.Common.Verify.Reference(row, "row");

			// create new
			EFS.RC.CC.CH.Entities.Surveys.Sessions.AnswerInfo dataObj = new EFS.RC.CC.CH.Entities.Surveys.Sessions.AnswerInfo();

			// ID
			dataObj.Answer.ID = EFS.DB.DataRow.Int32(row, "ID");

			// SURVEY_SESSION_ID
			dataObj.Answer.SurveySessionId = EFS.DB.DataRow.Int32(row, "SURVEY_SESSION_ID");

			// SURVEY_ANSWER_ID
			dataObj.Answer.SurveyAnswerId = EFS.DB.DataRow.Int32(row, "SURVEY_ANSWER_ID");

			// COMMENT
			dataObj.Answer.Comment = EFS.DB.DataRow.String(row, "COMMENT");

			// QUESTION_ID
			dataObj.QuestionId = EFS.DB.DataRow.Int32(row, "SURVEY_QUESTION_ID");

			// ok
			return dataObj;
		}


		/// GetAllAnswers
		public static EFS.RC.CC.CH.Entities.Surveys.Sessions.AnswerInfo[] GetAllAnswers(
			System.Int32 surveySessionId)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.CH.QRDConnection.New)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.CH.Entities.Surveys.Sessions.AnswerInfo>(
					"[dbo].[SurveySession_GetAnswers]",
					new EFS.DB.Parameters.Array("survey_session_id", surveySessionId),
					FromTableRow);
			}
		}

		/// GetAllAnswerByQuestionId
		public static EFS.RC.CC.CH.Entities.Surveys.Sessions.AnswerInfo[] GetAnswerByQuestionId(
			System.Int32 surveySessionId,
			System.Int32 answerId,
			EFS.DB.Connection connection)
		{
			// check
			EFS.Common.Verify.Reference(connection, "connection");

			// handle connection
			// get data
			return connection.DoExecuteTableReaderQuery<EFS.RC.CC.CH.Entities.Surveys.Sessions.AnswerInfo>(
				"[dbo].[SurveySession_GetAnswerByQuestionId]",
				new EFS.DB.Parameters.Array(
					new System.String[] { "survey_session_id", "answer_id" },
					new System.Object[] { surveySessionId, answerId },
					new System.Boolean[] { false, false }),
				FromTableRow);
		}
	}

}